.TH "mplex" "1" "2 June 2001" "MJPEG Tools Team" "MJPEG tools manual"

.SH "NAME"
.LP 
.br 
mplex \- MPEG 1/2 program/system stream multiplexer
.br 
.SH "SYNOPSIS"
.B mplex
.RB [ -f|--format
.IR format_code ]
.RB [ -i|--vdr-index] 
.IR index_pathname
.RB [ -v|--verbose
.IR num ]
.RB [ -b|--video-buffer
.IR video_buffer_size_kB [,
.IR video_buffer_size_kB ...] ]
.RB [ -L|--lpcm-params
.IR params [,
.IR params ... ] ]
.RB [ -r|--mux-bitrate
.IR muxed_bitrate_kbps ]
.RB [ -l|--mux-limit 
.IR num ]
.RB [ -O|--sync-offset
.IR num[\fBms\fP|\fBs\fP|\fBmpt\fP] ]
.RB [ -d|--subpicture-delay
.IR [\fBms\fP|\fBs\fP|\fBmpt|\fBc\fP] [:stream-id] [, delay[:stream-id] ]
.RB [ -R|--run-in
.IR num ]
.RB [ -V|--vbr]
.RB [ -C|--cbr]
.RB [ -s|--sector-size
.IR sector_size_B ]
.RB [ -p|--packets-per-pack
.IR num ]
.RB [ -h|--system-headers ]
.RB [ -S|--max-segment-size
.IR output_filesize_limit_MB ]
.RB [ -M|--split-segment]

.RB [ -?|--help ]
.BI -o|--output \ output_pathname_pattern \ input_file...

.SH "DESCRIPTION"
Mplex is a general-purpose audio/video multiplexer for MPEG-1/MPEG-2.
It accepts one or more MPEG-1/2 video stream, MPEG layer I/II/III, 
DTS, AC3 and LPCM audio streams and multiplexes them into a combined
program/system stream according to the constraints specified.  Many
different types of output structure are supported along with presets
for standard VCD and SVCD streams.  These latter can be burned to CD
using tools such as \fBvcdimager\fP(1) and played in stand-alone
players.

It is also capable of automatically splitting the output stream into
chunks of a specified size either independently or at sequence end/start
points in the input video stream.
.SH "GENERAL FUNCTION LETTERS"
.TP
.BI -o|--output \ output_filename_pattern
This mandatory option sets the pattern for the name(s) of output files.

An integer format code (e.g. %d) in the name is replaced by the number of
the file generated (see \fBprintf\fP(3)).
.TP
.BI -v|--verbose \ num
Set verbosity level to \fInum\fP:
 0 - warnings and errors only,
 1 - information as well,
 2 - really verbose.
.TP
.B -?|--help
Display a synopsis of the command syntax.
.br
.SH "FUNCTION LETTERS"
.TP
.BI -f|--format \ format_code
This command allows one of a number of convenient preset output
formats or generic MPEG1 or MPEG2 output to be selected. For the 
generic formats other function letters can be used to control many
aspects of the multiplexed stream.  For VCD/SVCD/DVD compliant output
the corresponding formats \fImust\fR be used as the standards require the
multiplexer to enforce a variety of special constraints on the structure
of the output stream.
.IP
 0 - Generic MPEG1.  A simple general-purpose MPEG1 format primarily suitable
for software decoders.  Buffer sizes and VBR must be specified.
Bit-rate can be auto-detected.
 1 - VCD.  Standard VCD.  Overrides other option settings.
 2 - User VCD.  VCD format but buffer size, bit rate and VBR can be set
manually.
 3 - Generic MPEG2.  Like 0 except MPEG2.
 4 - SVCD.  Standard SVCD.  Overrides other option settings.
 5 - User-rate SVCD.  SVCD format but buffer size bit rate and VBR can be set.
 6 - VCD Stills stream (mixed mode with hi-res and standard-res image streams
	 multiplexed are supported).
 7 - SVCD Stills stream.
 8 - DVD (with NAV sectors). Don't get too excited.  This is really a
 very minimal mux format.  It includes empty versions of the peculiar
 VOBU start sectors DVD VOB's include.  This is enough to persuade some
 hardware players to play the stream but is a long way from full DVD authoring.
 9 - DVD.  As above but without the empty VOBU sectors.
.TP
.BI -W|--workarounds \ workaround_flag\  \fR [, \fIworkaround_flag\fR ...]
.br
A comma-seperated list of flags that set special work-arounds for what
are suspected to be parser Bugs in widely used players. No workarounds are (currently) implemented but history suggests this may change quickly ;-)
.BI -i|--vdr-index \ index_pathname
This tells mplex to generate an index file for the output in the format
used by the 'vdr' (video disk recorder package). Useful if you want to
write output into vdr's recordings directory for playback on your
video recorder PC. This probably only useful in combination
with -f 9.
.TP
.BI -r|--mux-bitrate \ num
The total (non VBR) / peak (VBR) bit-rate of the output stream in k
Bits/sec. If unspecified and not set by a preset it is automatically
calculated from the input stream.
.TP
.BI -b|--video-buffer \ numlist
A comma-seperateed list of video decoder buffer sizes in KB for the
video streams (given in the order the video streams appear on the
command line).  The default is 46KB the (tiny) size specified for VCD.
The size to use for SVCD is the (more reasonable) 230KB.  If you are
encoding for a half-decent software decoder it makes sense to push
this up to 500K or more.
.TP
.BI -L|--lpcm-params
.I samples_per_sec:channels:bits_per_sample
.br
[,
.I samples_per_sec:channels:bits_per_sample
 ...]
.br
A comma-seperated list of paramter sets for the lpcm audio streams
(given in the order the lpcm streams appear on the command line).
Each parameter set comprises the sampling rate in Hz, the number of
channels, and the number of bits per sample seperated by colons.  For
example, the default 48kHz two-channel 16-bit audio would be specified
as 48000:2:16.
.IP

Note: these parameters are necessary because mplex expects raw LPCM
audio data without any headers.  That is: for each sample point a
group of 16,20, or 24 bit amplitude values, one for each
channel. Amplitude values are signed with the constituent bytes in
big-endian (most significant bytes first) order.  For 20 bit
samples I am not sure but what documentation I have suggests such
samples are padded at the lsb end so that they byte-align at the most
significant bits.

.TP
.BI -l|--mux-limit \ num
Multiplex limit.  Multiplex only the specified number of seconds.
Useful for tuning and debugging.
.TP
.BI -O|--sync-offset \ num[\fBms\fP|\fBs\fP|\fBmpt\fP|\fBc\fP]
Set the presentation timestamp offset of video stream w.r.t. audio stream (video-audio) in mSec.   This flag is used to produce a stream with synchronised
audio/video when one stream started before/after the other.  This is common
when transcoding as the synchronisation information is typically lost during
the (seperate) decoding/encoding of audio and video.
.IP
By appending 's', 'ms' or 'mpt' the offset can given in seconds,
milliseconds or MPEG clock ticks (1/90000th of a second) respectively.
If no suffix is given milliseconds are assumed.
.TP
.BI -d|--subpicture-delay \ num [\fBms\fP|\fBs|\fBmpt\fP|\fBc\fP] [:stream-id] [, delay[:stream-id]]
Specify offset of timestamps (video-subpicture) in msec sec, mpt or clock-ticks. If no suffix is given milliseconds are assumed.
.IP
The intention of the adding subtitle support was to enable mplex to mux all streams necessary for a DVD so that the mpeg2 stream created can be used directly for further dvd creation. Currently only ps1 streams (like created by tcextract) are supported
.IP 
Valid subtitle stream are in a range of 32-63 (including).
You may want to specify each stream you mplex, use "," to delimit each stream.
.IP
\fBExample:\fP
If you want to mux one video, one audio and two subtitle streams having delays of 500 and 1000 ms, the first shall have id 32, the second is 33 (Subtitle streams 0 and 1):
.IP
$ mplex -f 8 -o my_mpeg.mpeg -d 500:32,1000:33 video_in.mpv audio_in.m2a subtitle_0.ps1 subtitle_1.ps1
.TP
.BI -R|--run-in \ num
Set a non-default run-in (the time data is preloaded into buffers before decoding is scheduled) at the start of each sequence in video frame intervals.
By default a run-in matching the specified size of the video and audio buffers in the decoder and the type of multiplexing (constant or variable bit-rate) is selected automatically.
.TP
.B -V|--vbr
Force variable bit rate multiplexing even if selected profile defaults to constant-bit-rate.
.TP
.B -C||-cbr
Force constant bit rate multiplexing even if selected profile defaults to variable bit-rate.
.TP
.BI -s|--sector-size \ num
This option specifies the sector size of the output stream in bytes.
.TP
.BI -p|--packets-per-pack \ num
This option specifies the number of packets per pack in the output stream.
.TP
.BI -S|--max-segment-size \ num
This option specifies the maximum size of output files in MBytes (2^10)
When the limit is reached a  new file is started.
The default is (0) unlimited.
.IP
Note: This option is 
.I not
for splitting a long video across multiple VCD's or SVCD's.

It simply splits a single long sequence into in a way that prevents
bits of a video GOP(group of pictures) or audio frame being split
between chunks.  This is fine for formats like that
used for DVDs where all stream parameters appear every GOP.  However,
for VCD / SVCD it won't work as the players expect each file to start a 
new MPEG sequence.

For VCD / SVCD a different technique is used.  If mplex encounters a
sequence break (sequence end followed by start) in the input video
stream it starts a new output stream and file at the sequence start.
Thus to split a long video across VCD's/SVCD's you have to get the
MPEG video encoder to introduce sequence splits at the right points
(see mpeg2enc(1) for details of how to do this).
.TP
.B -M|--ignore-seqend-markers
This flag makes mplex ignore sequence end markers embedded in the
first video stream instead of switching to a new output file.  This is
sometimes useful splitting a long stream in files based on a -S limit
that doesn't need a run-in/run-out like (S)VCD.
.TP
.B -h|--system-headers
A system header is generated in every pack rather than just in the first.
.SH "DIAGNOSTIC OUTPUT"
When multiplexing using mplex you may get warning or error messages
complaining about buffer underflow.  This means that the bit-rate you
have specified is simply too low to permit the video and audio to be
played back without skipping.  The fix is to either reduce the
data-rate of the input material or increased the output stream bit-rate.
.SH "BUGS"
The multiplexer should handle MPEG(5.1) audio.
.SH AUTHOR
This man page was written by Andrew Stevens.
.br
If you have questions, remarks, problems or you just want to contact
the developers, the main mailing list for the MJPEG\-tools is:
  \fImjpeg\-users@lists.sourceforge.net\fP

For more info, see our website at
  \fIhttp://mjpeg.sourceforge.net\fP

.SH "SEE ALSO"
.BR mpeg2enc "(1), " mp2enc "(1), " lavrec "(1), " lavplay "(1), "
.BR lav2yuv "(1), " lav2wav "(1), " yuvscaler "(1)"
